package patrol.mobile.com.mobilepatrol.activity.office;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.OnClick;
import okhttp3.Call;
import patrol.mobile.com.mobilepatrol.R;
import patrol.mobile.com.mobilepatrol.activity.BaseActivity;
import patrol.mobile.com.mobilepatrol.api.Urls;
import patrol.mobile.com.mobilepatrol.bean.DeductionBean;
import patrol.mobile.com.mobilepatrol.utils.CommonUtil;
import patrol.mobile.com.mobilepatrol.utils.GsonUtil;
import patrol.mobile.com.mobilepatrol.utils.net.HttpCallBack;
import patrol.mobile.com.mobilepatrol.utils.net.HttpSender;

/**
 * 考核明细
 */
public class DeductionActivity extends BaseActivity {


    @BindView(R.id.tv_koufenyuanyin)
    TextView tvKoufenyuanyin;
    @BindView(R.id.btn_back)
    Button btnBack;

    private static final String FORM_WHAT = "FROM_WHAT";
    private static final String ID = "ID";
    @BindView(R.id.tv_first1)
    TextView tvFirst1;
    @BindView(R.id.tv_first2)
    TextView tvFirst2;
    @BindView(R.id.tv_second1)
    TextView tvSecond1;
    @BindView(R.id.tv_second2)
    TextView tvSecond2;
    @BindView(R.id.tv_three1)
    TextView tvThree1;
    @BindView(R.id.tv_third)
    TextView tvThree2;
    @BindView(R.id.tv_four1)
    TextView tvFour1;
    @BindView(R.id.tv_four2)
    TextView tvFour2;
    @BindView(R.id.rl_content)
    RelativeLayout rlContent;
    private int fromWhat; //1.科室绩效 2.科员 3.收费服务区 4.分局
    private String id;

    public static void show(Context context, int fromWhat, String id) {
        Intent intent = new Intent(context, DeductionActivity.class);
        intent.putExtra(FORM_WHAT, fromWhat);
        intent.putExtra(ID, id);
        context.startActivity(intent);
    }

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_deduction;
    }

    @Override
    public void initView() {
        super.initView();
        fromWhat = getIntent().getIntExtra(FORM_WHAT, 0);
        id = getIntent().getStringExtra(ID);
        setTitles();
    }

    @Override
    public void initData() {
        super.initData();
        if (fromWhat == 1) {
            requestData1(Urls.ORG_CHECK_ENTITY);
        } else if (fromWhat == 2) {
            requestData1(Urls.ORG_USER_CHECK_ENTITY);
        } else if (fromWhat == 3) {
            requestData1(Urls.ORG_SUB_BUREAU_ENTITY);
        } else if (fromWhat == 4) {
            requestData1(Urls.ORG_SERVICE_AREA_ENTITY);
        }
    }

    private void requestData1(String url) {
        HttpSender sender = new HttpSender(this, baseUrl, url);
        sender.requestPost("id", id, new HttpCallBack(sender) {
            @Override
            public void onError(String code, Call call, Exception e) {

            }

            @Override
            public void onResponse(String code, String response) {
                DeductionBean deductionBean = GsonUtil.GsonToBean(response, DeductionBean.class);
                setViewData(deductionBean);
            }
        });
    }

    private void setViewData(DeductionBean deductionBean) {
        tvKoufenyuanyin.setText(deductionBean.getReason());
        if (fromWhat == 1) {
            tvFirst1.setText("考核月度");
            tvFirst2.setText(deductionBean.getPeriod());
            tvSecond1.setText("责任部门");
            tvSecond2.setText(deductionBean.getOrgName());
            tvThree1.setText("考核得分");
            tvThree2.setText(deductionBean.getTotalScore() + "分");
            rlContent.setVisibility(View.GONE);
        } else if (fromWhat == 2) {
            tvFirst1.setText("考核月度");
            tvFirst2.setText(deductionBean.getPeriod());
            tvSecond1.setText("责任部门");
            tvSecond2.setText(deductionBean.getOrgName());
            tvThree1.setText("责任人");
            tvThree2.setText(deductionBean.getUpUserName());
            tvFour1.setText("考核得分");
            tvFour2.setText(deductionBean.getTotalScore() + "分");
        } else if (fromWhat == 3) {
            tvFirst1.setText("考核季度");
            tvFirst2.setText(deductionBean.getPeriod());
            tvSecond1.setText("责任部门");
            tvSecond2.setText(deductionBean.getCheckName());
            tvThree1.setText("考核部门");
            tvThree2.setText(deductionBean.getOrgName());
            tvFour1.setText("考核得分");
            tvFour2.setText(deductionBean.getTotalScore() + "分");
        } else if (fromWhat == 4) {
            tvFirst1.setText("考核季度");
            tvFirst2.setText(deductionBean.getPeriod());
            tvSecond1.setText("责任部门");
            tvSecond2.setText(deductionBean.getCheckName());
            tvThree1.setText("考核部门");
            tvThree2.setText(deductionBean.getOrgName());
            tvFour1.setText("考核得分");
            tvFour2.setText(deductionBean.getTotalScore() + "分");
        }
    }

    private void setTitles() {
        iv_back.setImageResource(R.mipmap.up_white);
        iv_back.setVisibility(View.VISIBLE);
        iv_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                CommonUtil.exitActivityAndBackAnim(DeductionActivity.this, true);
            }
        });
        tv_center_title.setVisibility(View.VISIBLE);
        if (fromWhat == 1) {
            tv_center_title.setText("扣分明细");
        } else if (fromWhat == 2) {
            tv_center_title.setText("科员扣分明细");
        } else if (fromWhat == 3) {
            tv_center_title.setText("扣分明细");
        } else if (fromWhat == 4) {
            tv_center_title.setText("考核明细");
        }
    }

    @Override
    public void setListener() {

    }


    @OnClick(R.id.btn_back)
    public void onViewClicked() {
        finish();
    }
}
